<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>工资管理</title>
<link rel="stylesheet" type="text/css" href="../../css/cm-default.css" />
<link rel="stylesheet" type="text/css" href="../../css/main.css" />
<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/Aqua/css/ligerui-all.css" />
<link rel="stylesheet" type="text/css" href="../../lib/ligerUI/skins/ligerui-icons.css" />
<link rel="stylesheet" type="text/css" href="../../lib/bootstrap/css/bootstrap.css"/>
<link type="text/css" rel="stylesheet" href="../../css/public.css"  />
<link type="text/css" rel="stylesheet" href="../../css/pub.css"  />
<script type="text/javascript" src="../../lib/jquery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../../lib/jquery-validation/jquery.validate.min.js" ></script>
<script type="text/javascript" src="../../lib/jquery-validation/jquery.metadata.js" ></script>
<script type="text/javascript" src="../../lib/jquery-validation/messages_cn.js" ></script>
<script type="text/javascript" src="../../lib/ligerUI/js/ligerui.all.js" ></script>
<script type="text/javascript" src="../../js/common.js" ></script>
<script src="../../lib/autoInput/AutoInput.js" type="text/javascript"></script>
<script type="text/javascript" src="../../js/pub.js"></script>
<script type="text/javascript" src="../../lib/bootstrap/js/bootstrap.js" ></script>
<script type="text/javascript" src="../../lib/fileupload/ajaxfileupload.js" ></script>

<script type="text/javascript">
	var GridNameCode = [
        {"Key_Nvarchar":"userName","Value_Nvarchar":"姓名"},
        {"Key_Nvarchar":"userCode","Value_Nvarchar":"工号"}
        /*{"Key_Nvarchar":"deptId","Value_Nvarchar":"供应商"}
        {"Key_Nvarchar":"stateS","Value_Nvarchar":"状态"}*/
    ] ;
	$(function() {
           InitAutoInput("gridName", GridNameCode, { key: "Key_Nvarchar", val: "Value_Nvarchar", format: "Value_Nvarchar" }, 'json');
           var searchHeight = $(".commenGotoSite").outerHeight();
           $(".searchContent").height(searchHeight);
      		$(".listTable").height($(window).height()-searchHeight);
       });
       function selectToggle(obj){
       	if($(".searchForm").get(0).style.display=="none"){
       		var searchHeight = $(".commenSearch").outerHeight()+$(".searchForm").outerHeight();
       		$(".searchForm").attr("style","display:block");
       		$(".searchContent").height(searchHeight);
       		$(".listTable").height($(window).height()-searchHeight);
       		$("#searchMark").removeClass("glyphicon glyphicon-menu-down");
       		$("#searchMark").addClass("glyphicon glyphicon-menu-up");
       	}else{
       		var searchHeight = $(".commenSearch").outerHeight();
       		$(".searchForm").attr("style","display:none");
       		$(".searchContent").height(searchHeight);
       		$(".listTable").height($(window).height()-searchHeight);
       		$("#searchMark").removeClass("glyphicon glyphicon-menu-up");
       		$("#searchMark").addClass("glyphicon glyphicon-menu-down");
       	}
       	// grid 重新加载数据
		defGrid.loadData();
       }	
             
</script>
		
<script type="text/javascript">
var defGrid,paramS;
paramS =new Object();
$(function(){
    defGrid = $("#query_list").ligerGrid({
        columns:[
			{display:'Id',name:'salaryid',width:80,minWidth:80,align:'left',hide:true},
            {display:'姓名',name:'username',width:80,minWidth:80,align:'left'},
            {display:'工号',name:'userid',width:80,minWidth:80,align:'left'},
            {display:'所属公司',name:'company_id',width:100,minWidth:60,render:company_org},
            {display:'所属部门',name:'dept_id',width:100,minWidth:60,render:dept_org},
            {display:'基本薪资',name:'base_wage',width:80,minWidth:80,align:'left'},
            {display:'加班补贴',name:'allowance',width:80,minWidth:60,align:'left'},
            {display:'缺勤扣款',name:'absence_deduct',width:80,minWidth:60,align:'left'},
            {display:'工资月份',name:'sal_date',width:80,minWidth:80,align:'left'},
            {display:'实发工资',name:'actual_salary',width:80,minWidth:60,align:'left'},
            {display:'制表状态',name:'sal_state',width:80,data:status,render:switcher}
        ],
        pageSize:10,
        usePager: true,
        sortName:'id',
        width:'100%',
        height:'100%',
        postData:paramS,
        dataAction:'server',
        checkbox:false,
        rownumbers:false,
        fixedCellHeight:false,
        colDraggable:true,
        enabledEdit:false,
        clickToEdit:false,
        onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
        sqlid:"salary.select.salaryinfo.query",
        url: '/salary/query',
        contentType : "application/json; charset=utf-8",
        param_status:'rbac.status',
        param_org_type:'rbac.org_type',
        param_org:'org_list'
    });
    $("#pageloading").hide();
    
});

function switcher(item) {
    return paramRender(item, defGrid.options.param_status, item.sal_state);
}

function company_org(item) {
	var orgTpye = new Object();
	orgTpye.org_type ="0";
    return paramRender(item, defGrid.options.param_org, item.company_id,orgTpye,false);
}

function dept_org(item) {
	var orgTpye = new Object();
	orgTpye.org_type ="1";
    return paramRender(item, defGrid.options.param_org, item.dept_id,orgTpye,false);
}

var getStatus = new function () {
    return getData('rbac.status');
}
var get_org_list=new function () {
    return getData('org_list');
}

var get_org_type = new function () {
    return getData('rbac.org_type');
}


function toQuery(item, page, pageSize) {
    //var param = new Object();
    paramS.username = $("#username").val();
    paramS.userid=$("#userid").val();
    paramS.sal_state = $("#sal_state").val();
    // l-list 线性结构，默认；t-tree 树型结构
    paramS.rt='l';
    //重置页码
    defGrid.set({
        page : 1,
        newPage : 1,
        postData : paramS
    });
    // grid 重新加载数据
    defGrid.loadData();
}

//通用查询 ldz start
function toQuery_common() {
	var key = $("#gridNameCode").val();
	var val = $("#gridName").val();
	key = key.split("Q")[0];
	//设置查询条件参数
	switch (key)
	{
		case "username":
			paramS.username = val;
		  	break;
		case "userid":
			paramS.userid = val;
		  	break;
		default:
			paramS.username = "";
			paramS.userid = "";
	}
	
	// l-list 线性结构，默认；t-tree 树型结构
	paramS.rt='l';
	
	//重置页码
	defGrid.set({
		page : 1,
		newPage : 1,
		postData : paramS
	});
	// grid 重新加载数据
	defGrid.loadData();
}

//新增
function new_stockp() {
	parent.f_addTab('new_salary','新增员工工资信息','./html/salary/salary_insert.html');
}
//编辑
function openModify() {
	var row = defGrid.getSelectedRow();
	if (!row) {
		$.ligerDialog.error('请先选择要编辑的员工工资记录。','编辑');
		return;
	}
	var salaryid = row.salaryid;
	parent.f_addTab('modify_salary','修改员工工资信息','./html/salary/salary_edit.html?salaryid='.concat(salaryid));
}

//明细页面 ldz
function openMx(){
	var row = defGrid.getSelectedRow();
	if (!row) {
		$.ligerDialog.error('请先选择要查看的员工工资记录。','明细');
		return;
	}
	var salaryid = row.salaryid;
	parent.f_addTab('mx_salary','员工工资明细','./html/salary/salary_detail.html?salaryid='.concat(salaryid));
}
	
//删除处理 
function deleteRow() {
	var row = defGrid.getSelectedRow();
    if (!row) {
        $.ligerDialog.error('请先选择要删除的员工工资记录。','错误');
        return;
    }
    var salaryid = row.salaryid;
    $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
        if (!r)
          return;
       toDel(salaryid);
    })
}

// 删除处理业务处理
function toDel(id) {
    ajaxSubmitGet("/salary/deleteSalary/" + id,function(data) {
        if (data) {
            if (parseInt(data['status']) > 0) {
                toQuery();
                $.ligerDialog.success('删除成功');
            } else {
                $.ligerDialog.error('删除失败');
            }
        }
    });
}

//下载Excel模板
function dowmloadExcel() {
    var url = "/salary/downloadSalaryTemp";
    window.open(url);
}


//导出Excel
function exportExcel() {
	var param = new Object();
	param.sal_state = $("#sal_state").val();
	param.username = $("#username").val();
	param.userid=$("#userid").val();
    var data=JSON.stringify(param);
    var url = "/salary/exportSalary?data="+data;
    window.open(url);
}

//导入Excel
function importExcel() {
	$('#addMx_Modal').modal('show');
}

$(function(){
	$('#pop_add_button').bind('click',function(){
		$.ajaxFileUpload ({
		    	type: "POST",  //提交方式
		        url: '/salary/salaryExcelUpload', //用于文件上传的服务器端请求地址
		        secureuri: false,           //一般设置为false
		        fileElementId: $("input#file").attr("id"), //文件上传控件的id属性  <input type="file" id="file" name="file" /> 注意，这里一定要有name值   
		        dataType: 'text',//返回值类型 一般设置为json
		        complete: function () {//只要完成即执行，最后执行
		        },
		        success: function (data) {  //服务器成功响应处理函数
		        	alert("导入Excel文件成功！");
		        	// grid 重新加载数据
		            defGrid.loadData();
		        },
		        error: function (data)//服务器响应失败处理函数
		        {
		        	alert("导入Excel文件发生错误！");
		        }
		    }
		)
	});
})

</script>

<style type="text/css">
	label{margin: 5px 20px 5px 15px;}
	.fields{height:35px;padding-top:5px;}
	.dict-info{width: 260px;padding: 10px;}
	.diff {margin:3px 0;}
	.lineD {width:99%;float:left;position:relative;overflow:hidden;margin:10px 0 2px 2px}
	.labelD {width:13%;position:relative;float:left;padding-top:3px;}
	.dplD {width:36%;position:relative;float:left;}
	.title{font-size:14px;font-weight:bold;background-position:left;padding-left:18px;}
	.l-dialog-content-nopadding{padding:0 !important;}
</style>
</head>
<body>
<div id="list_tab contextHeight">
	<div class="searchContent">
		<div class="commenSearch">
   			<div class="commenGotoSite">
   				
   				<button type="button" onclick="new_stockp();" class="btn btn-primary btn-sm ">
	    			&nbsp;<span class="glyphicon glyphicon-plus"></span>
	    		</button>
	    		<button type="button" onclick="openModify();" class="btn btn-primary btn-sm">
	    			&nbsp;<span class="glyphicon glyphicon-pencil"></span>
	    		</button>
	    		<button type="button" onclick="openMx();" class="btn btn-primary btn-sm">
	    			&nbsp;<span class="glyphicon glyphicon-eye-open"></span>
	    		</button>
	    		<button type="button" onclick="deleteRow();" class="btn btn-primary btn-sm">
	    			&nbsp;<span class="glyphicon glyphicon-trash"></span>
	    		</button>
	    		<button type="button" onclick="importExcel();" class="btn btn-primary btn-sm">
	    			&nbsp;<span class="glyphicon glyphicon-import"></span>导入
	    		</button>
	    		<button type="button" onclick="exportExcel();" class="btn btn-primary btn-sm">
	    			&nbsp;<span class="glyphicon glyphicon-export"></span>导出
	    		</button>
	    		<button type="button" onclick="dowmloadExcel();" class="btn btn-primary btn-sm">
	    			&nbsp;<span class="glyphicon glyphicon-download"></span>下载工资表模板
	    		</button>
	    		
   			</div>
   			<div class="commenSearchSite">
   				<div class="form-inline">
				  <div class="form-group contextWidth">
		    		<div class="autoBox">
		    			<span class="glyphicon glyphicon-search"></span>
                        <span class="commenSearchTitle"></span>
                        <input type="text" class="autoInput form-control input-sm" id="gridName" style="width:75%;" value="" autocomplete="off" />
                        <div class="autoList">
                        </div>
                        <input id="gridNameCode" name="gridNameCode" type="hidden" value="" />
                        <div style="display:inline-block;position:relative;">
                        	<span class="zkbutton" onclick="selectToggle(this);">
	                        	<span id="searchMark" class="glyphicon glyphicon-menu-down"></span>
	                        </span>
                        </div>
                        &nbsp;&nbsp;
			  			<button type="button" onclick="toQuery_common();" class="btn btn-primary btn-sm">查询</button>
                    </div>
				  </div>
				</div>
   			</div>
   		</div>
	    		
		<div class="searchForm" style="display:none">
   			<form id="form1" class="form-inline" action="">
			  <div class="form-group">
			    <label for="username">姓名:</label>
			    <input type="text" class="form-control input-sm" id="username" />
			  </div>
			  <div class="form-group">
			    <label for="userid">工号:</label>
			    <input type="text" class="form-control input-sm" id="userid" />
			  </div>
			  <div class="form-group">
			    <label for="deptId">部门:</label>
			    <input type="text" class="form-control input-sm" id="deptId" />
			  </div>
			  <div class="form-group" style="display:none;">
			    <label for="sal_state">状态:</label>
			    <select name="sal_state" id="sal_state" param="rbac.status" first="" class="form-control input-sm">
		    	</select>
			  </div>
			  &nbsp;&nbsp;
			  <button type="button" onclick="toQuery();" class="btn btn-primary btn-sm">查询</button>
			  &nbsp;&nbsp;
			  <button type="button" onclick="toReset('#orgname,#SHORTFOR,#dictStatus');" class="btn btn-primary btn-sm">清空</button>
			</form>
   		</div>
	</div>
	<div id="pop_div">
	 	<div class="modal fade" id=addMx_Modal tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title" id="exampleModalLabel">导入工资信息:</h4>
		      </div>
		      <div class="modal-body">
		        <div id="form_table">
		        	<input type="file" name="file" id="file">
		        </div>
		      </div>
		      <div class="modal-footer">
		        <button type="button" id="pop_add_button" class="btn btn-primary" data-dismiss="modal">导入</button>
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		      </div>
		    </div>
		  </div>
		</div>
	</div>
					   		
    <div class="listTable">		
    <div class="split_line"></div>
    <div id="query_list"></div>
    </div>
</div>
<div id="pageloading"></div>
</body>
</html>